<?php
class Database{
	
	protected static $DB_Name;
	protected static $DB_Open;
	protected static $DB_Conn;

	public function __construct($database, $hostname, $hostport, $username, $password){
		self::$DB_Name = $database;
		self::$DB_Conn = mysql_connect($hostname . ":" . $hostport, $username, $password);
		if (!self::$DB_Conn) { die('Critical Stop Error: Database Error<br />' . mysql_error()); }
		mysql_select_db(self::$DB_Name, self::$DB_Conn);
	}
	
	public function query($sql, $return_format = 0){
		$query = mysql_query($sql, self::$DB_Conn) OR die(mysql_error());
		switch ($return_format){
			case 1:
				while($result = mysql_fetch_row($query)){ 
					$array[] = $result;
				} 			
				break;
			case 2:		
				while($result = mysql_fetch_array($query)){ 
					$array[] = $result;
				} 			
				break;
			case 3:
				while($result = mysql_fetch_row($query)){ 
					$array[] = $result[0];
				} 			
				break;
			case 4:
				$result = mysql_fetch_row($query);
				$array = $result[0];
				break;
			
			default:
				$array = $query;
		}
		return $array;
	}
	
	public function insert($sql){
		$insert = mysql_query($sql, self::$DB_Conn) OR die(mysql_error());
		return $insert;
	}
	
	public function delete($sql){
		$insert = mysql_query($sql, self::$DB_Conn) OR die(mysql_error());
		return $insert;
	}	
	
	public function update($sql){
		$insert = mysql_query($sql, self::$DB_Conn) OR die(mysql_error());
		return $insert;
	}
	
}

?>